package com.hh.util;

import com.hh.entity.Users;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Component
public class RedisUtil {
    @Resource
    RedisTemplate redisTemplate;
    public Users byIdQueryUsersInfo(String id){
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer(Users.class));
        Users users=(Users)redisTemplate.opsForValue().get(id);
        return users;
    }
    public void putUsersInfo(String key,Users value){
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer(Users.class));
        redisTemplate.opsForValue().set(key,value,30, TimeUnit.SECONDS);
    }

}
